package com.sa.commons.aop.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;

import com.sa.commons.dao.hiber.basic.HibernateSessionFactory;



public class SessionCloseFilter implements Filter {

	private static Log log=LogFactory.getLog(SessionCloseFilter.class);
	
	public void destroy() {

	}

	public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException,
			ServletException {
		log.info("session interceptor has started");
		Session session=HibernateSessionFactory.getSession();
		if (session!=null) {
			session.flush();
			session.close();
		}
		log.info("session interceptor has finished");
		arg2.doFilter(arg0, arg1);
	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}

}
